import datetime
import os.path
import sys

import webdriver_manager
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.edge.options import Options


class Driver:
    driver = ""
    # 默认构造函数
    def __init__(self):
        # 1.打开浏览器驱动管理
        driver_path = 'D:\AppGallery\driver\msedgedriver\edgedriver_win64\msedgedriver.exe'
        edge_options = Options()
        edge_options.add_argument("--remote-allow-origins=*")
        # 2.创建edge浏览器驱动对象
        self.driver = webdriver.Edge(service=Service(driver_path), options=edge_options)

        # # 谷歌浏览器，创建ChromeOptions对象，用于配置浏览器的启动选项
        # option = webdriver.ChromeOptions()
        # self.driver = ChromeDriverManager().install()
        # # 使用webdriver.Chrome()启动Chrome浏览器，并传入service和options参数
        # self.driver = webdriver.Chrome(service=Service(self.driver),options=option)

        # # Firefox浏览器
        # option = webdriver.FirefoxOptions()
        # self.driver = webdriver_manager.firefox.GeckoDriverManager
        # self.driver = webdriver.Firefox(options=option)

        # # EDGE浏览器
        # self.driver = EdgeChromiumDriverManager().install()
        # edge_options = webdriver.EdgeOptions()
        # edge_options.add_argument("--remote-allow-origins=*")
        # self.driver = webdriver.Edge(service=Service(self.driver), options=edge_options)
        # # self.driver = webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager().install()))

    def Get_ScreenShot(self):
        # 自动创建每天的保存截图的文件，并命名为当天时间
        curDay = datetime.datetime.now().strftime("%Y-%m-%d")
        if not os.path.exists("./images/" + curDay):
            os.mkdir("./images/" + curDay)
        # filename = datetime.datetime.now().strftime("%H%M%S") + ".png"
        # 加文件名
        filename = sys._getframe().f_back.f_code.co_name + "-" + datetime.datetime.now().strftime("%H%M%S") + ".png"
        self.driver.save_screenshot("./images/" + curDay + "/" + filename)

SurveyExaminationSystem_Driver = Driver()
